<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >  
    <ui:composition template="layout.xhtml">

        <ui:define name="corpo">
            <h:form id="incluir_form_entrada" acceptcharset="utf-8" prependId="false"> 
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexSelo.xhtml')}" value="Selo" update="@form" immediate="true"/> >
                    <p:commandLink  value="Cadastrar Selo" update="@form" immediate="true"/>
                </div>
                <p:panel header="Cadastrar Entrada de Selo">
                    <p:messages autoUpdate="true" id="msg"/>
                    <fieldset>
                        <legend>Cabeçalho da Entrada</legend>
                        <br/>
                        <h:panelGrid id="entrada" columns="2" width="900" 
                                     styleClass="textAlignRight" columnClasses="textAlignRight"> 
                            <h:outputLabel value="N° Nota :"/>
                            <p:inputText  id="notaselo" 
                                          value="#{managerEntrada.entradaSelo.numeroNota}" size="23"/>

                            <p:row>
                                <h:outputLabel value=" * " style="color:red;"/>
                                <h:outputLabel value="Fornecedor: "/>
                            </p:row>
                            <p:row>
                                <p:autoComplete id="fornecedor" 
                                                value="#{managerEntrada.entradaSelo.fornecedor}" 
                                                completeMethod="#{managerFornecedor.completeFornecedor}"  
                                                var="p" itemLabel="#{p.nome}" itemValue="#{p}" 
                                                converter="fornecedorConverter" forceSelection="true" 
                                                converterMessage="Erro, verifique o Fornecedor" 
                                                minQueryLength="3" dropdown="true" required="true" 
                                                size="20"
                                                requiredMessage="O campo 'Fornecedor' é obrigatório"> 
                                    <p:ajax event="itemSelect" listener="#{managerEntrada.handleSelect}"/>                                        
                                </p:autoComplete>
                                <p:message for="fornecedor"  />
                            </p:row>
                            <p:row>
                                <h:outputLabel value=" * " style="color:red;float:right"/>
                                <h:outputLabel value="Data da Nota: " /> 
                            </p:row>
                            <p:row>
                                <p:calendar value="#{managerEntrada.entradaSelo.dataNote}" label="Data" 
                                              id="data_nota" mode="popup" showOn="both" 
                                            pattern="dd/MM/yyyy" required="true" 
                                            requiredMessage="O campo 'Data entrada' é obrigatorio" size="20"/>

                                <p:message for="data_nota"  />
                            </p:row>
                            <h:outputLabel value="Comentário :"/>
                            <p:inputTextarea  id="comentario" cols="94"  
                                              autoResize="true" 
                                              value="#{managerEntrada.entradaSelo.comentario}"/>
                        </h:panelGrid>
                    </fieldset>
                    <br/>
                    <fieldset id="fieldSet">
                        <legend>Entrada</legend>
                        <h:panelGrid columns="1" border="0" id="panelAll" width="950" >
                            <h:panelGrid columns="6"  id="panelEntrada"   border="0" styleClass="textAlignRight" columnClasses="textAlignRight"> 
                                <p:row>
                                    <h:outputLabel value=" * " style="color:red;float:right"/>
                                    <h:outputLabel value="Tipo Selo: "/>

                                </p:row>
                                <p:row>
                                    <p:autoComplete id="tipoSelo" 
                                                    value="#{managerEntrada.detalhe.tipoSelo}" 
                                                     completeMethod="#{managerTipoSelo.completeTipoSelo}"  
                                                    var="p" itemLabel="#{p.nome}"   itemValue="#{p}" 
                                                    converter="tipoSeloConverter" forceSelection="true" 
                                                    converterMessage="Erro, verifique o Tipo Selo"
                                                    minQueryLength="3" dropdown="true" required="true"
                                                    panelStyleClass="autoCompPanel" style="width:50px;"
                                                    requiredMessage="O campo 'Tipo Selo' é obrigatório"> 
                                        <p:ajax event="itemSelect" listener="#{managerEntrada.handleSelectTipoSelo}"/>   
                                        <p:column>  
                                            <table>
                                                <tr  style="height:20px; background-color: \##{p.corSelo.cor};">
                                                    <td style="width: 20px;"></td>
                                                </tr>
                                            </table>
                                        </p:column>
                                        <p:column>  
                                            #{p.nome}
                                        </p:column>  
                                    </p:autoComplete>
                                    <p:message for="tipoSelo"  />
                                </p:row>

                                <h:outputLabel value="Serie :"/>
                                <p:inputText id="serie" value="#{managerEntrada.detalhe.serie}" />
                                
                                <h:outputLabel value="Preço :"/>
                                <p:inputText id="preco" value="#{managerEntrada.detalhe.preco}" onkeypress="jQuery(this).autoNumeric({aSign: 'R$ ', aSep: '.', aDec: ','} );">
                                    <f:convertNumber type="currency" />
                                </p:inputText>

                                <h:outputLabel  value="Número Inicial :"/>
                                <p:inputText id="numIni"  value="#{managerEntrada.detalhe.numIni}" 
                                             required="true" label="Número Inicial" title="Número Inicial"
                                             onkeypress="jQuery(this).autoNumeric({aSep: '', aPad: false});"/>
                                
                                <h:outputLabel value="Quantidade :"/>
                                <p:inputText id="qtd" value="#{managerEntrada.qtd}" onkeypress="jQuery(this).autoNumeric({ aSep: '', aPad: false} );"/>
                                
                                <h:outputLabel  value="Número Final :"/>
                                <p:inputText id="final" value="#{managerEntrada.numFim}" onkeypress="jQuery(this).autoNumeric({ aSep: '', aPad: false} );"/>


                            </h:panelGrid>
                            <p:row>
                                <div class="buttonAction">
                                    <p:commandButton value="Adicionar" icon="ui-icon-circle-plus" process="@this, panelAll" update="tabledetalhe, panelAll, msg"
                                                     actionListener="#{managerEntrada.adicionarDetalhe()}" />                                    
                                    <p:commandButton icon="ui-icon-close" actionListener="#{managerEntrada.reinitDetalhe()}" value="Limpar"  update="@form" immediate="true"/>
                                </div>
                            </p:row>
                            <p:dataTable id="tabledetalhe" var="detal" 
                                         value="#{managerEntrada.listDetalhe}"
                                         rowIndexVar="rowid" emptyMessage="Nenhuma entrada de selo">
                                <f:facet name="header">
                                    <h:outputText value="Detalhe da Entrada de Selos"/>
                                </f:facet>
                                <p:column headerText="Cor" style="width: 50px">
                                    <h:outputText value=""/>
                                    <table>
                                        <tr class="borderZero" style="height:30px; background-color: \##{detal.tipoSelo.corSelo.cor};">
                                            <td class="borderZero" style="width: 20px;"></td>
                                        </tr>
                                    </table>
                                </p:column>
                                <p:column headerText="Tipo Selo" style="width: 50px; text-align: center;">
                                    <h:outputText value="#{detal.tipoSelo.nome}"/>
                                </p:column>
                                <p:column headerText="Serie" style="width: 50px; " >
                                    <h:outputText value="#{detal.serie}" style="float: right"/>
                                </p:column>
                                <p:column headerText="Preço" style="width: 50px">
                                    <h:outputLabel  value="#{detal.preco}"  style="float: right" >
                                        <f:convertNumber type="currency" />
                                    </h:outputLabel>
                                </p:column>
                                <p:column headerText="Número Inicial" style="width: 50px">
                                    <h:outputText value="#{detal.numIni}" style="float: right"/>
                                </p:column>
                                <p:column headerText="Quantidade" style="width: 40px">
                                    <h:outputText value="#{detal.qtd}" style="float: right"/>
                                </p:column>
                                <p:column headerText="Número Final" style="width: 50px">
                                    <h:outputText value="#{detal.numFim}" style="float: right"/>
                                </p:column>
                                <p:column style="width: 20px;" headerText="Opções">
                                    <p:commandButton  style="width: 30px; height: 30px; float: right;"
                                                      onclick="removeRC({param:#{rowid}})" icon="editar"/>
                                    <p:commandButton style="width: 30px; height: 30px; float: right;" 
                                                     icon="ui-icon-trash"  actionListener="#{managerEntrada.removeList(detal)}" process="@this" update="@form" immediate="true"/>

                                </p:column>
                            </p:dataTable>                           

                            <p:remoteCommand name="removeRC"
                                             update="tabledetalhe, panelAll" process="@this" actionListener="#{managerEntrada.editList()}">
                            </p:remoteCommand>

                        </h:panelGrid>
                    </fieldset>
                    <div class="buttonAction">
                        <p:commandButton icon="ui-icon-disk" id="submit" value="Salvar" 
                                         actionListener="#{managerEntrada.salvar()}"
                                         update="@form" process="@this, entrada" 
                                         onclick="statusDialog.show();" 
                                         oncomplete="statusDialog.hide();"/>
                        <p:commandButton value="Cancelar"  actionListener="#{managerIndex.redirect('indexSelo.xhtml')}"
                                         update="@form" immediate="true" icon="ui-icon-arrowreturnthick-1-w" />
                    </div>


                </p:panel>
                <p:dialog modal="true" widgetVar="statusDialog" header="Gerando Selos"   
                          draggable="false" closable="false">  
                    <p:graphicImage value="/media/img/ajaxloadingbar.gif" />  
                </p:dialog>
               

            </h:form>
        </ui:define>
    </ui:composition>
</html>

